package com.example.project.service.serviceimpl;

import com.example.project.mapper.ResultMapper;

import com.example.project.pojo.Result;
import com.example.project.pojo.Three;
import com.example.project.pojo.Zong;
import com.example.project.service.ResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class ResultServiceImpl implements ResultService {
    //依赖注入
    @Autowired
    ResultMapper resultMapper;

    @Override
    public String getMathAll(){
        return resultMapper.getMath();
    }


    @Override
    public void addResult(Result result){
        resultMapper.addResult(result);
    }

    @Override
    public List<Three> getSumResult(){
        return resultMapper.getSumResult();
    }

    @Override
    public List<Integer> getAllResult(){
        List<Three> list = resultMapper.getAllResult();
        List<Integer> list1 = new ArrayList<>();
        for(int i=0;i<list.size();i++){
            Three three = list.get(i);
//            three.getMath();
//            three.getEnglish();
//            three.getChinese();
            int zong = three.getChinese()+three.getMath()+ three.getEnglish();
//            double avg = zong/3;
            list1.add(zong);
        }
        return list1;
    }

    @Override
    public List<Double> avgAllResult(){
        List<Three> list = resultMapper.getAllResult();
        List<Double> list2 = new ArrayList<>();
        for(int x=0;x<list.size();x++){
            Three three = list.get(x);
            int zong = three.getChinese()+three.getEnglish()+ three.getMath();
            double avg = zong/3d;
            list2.add(avg);
        }
        return list2;
    }
}
